$(document).ready(function(){  
/*	//设置藏品分类级联下拉框
	var doms_cpfl = ["DJH_CPFL1","DJH_CPFL2","DJH_CPFL3"];
	selectThree(url_cplb,doms_cpfl);
	//设置藏品时代级联下拉框
	var doms_sd = ["DJH_SD1","DJH_SD2","DJH_SD3","DJH_SD4"];
	selectFour(url_nd,doms_sd);*/
   //获取Url中的参数
	$("#functionNav").attr("href",navAddr);
   var cpid =GetQueryString("id");
   /*var page =GetQueryString("page");
   if(cpid=="" || page==""){
	   alertFunc("获取参数失败！");
	   return false;
   }*/
	//获取并填充文物普查类别
	var wwlbJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do",{'tableName':'jb_wwlb'});
	if(wwlbJson.status=="ok"){
		loadSelect("#form_cpinfo select[name=cplb]",wwlbJson.rows,'id','name');
	}else{
		alertFunc("获取藏品类别列表失败！");
		return false;
	}	
	//获取并填充数量单位
	var sldwJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do",{'tableName':'jb_ctsldw'});
	if(sldwJson.status=="ok"){
		loadSelect("#form_cpinfo select[name=ctsldw]",sldwJson.rows,'id','name');
	}else{
		alertFunc("获取传统数量单位列表失败！");
		return false;
	}	
	//获取并填充数量单位
	var sjsldwJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do",{'tableName':'jb_sjsldw'});
	if(sldwJson.status=="ok"){
		loadSelect("#form_cpinfo select[name=sjsldw]",sjsldwJson.rows,'id','name');
	}else{
		alertFunc("获取实际数量单位列表失败！");
		return false;
	}	
	//获取并填充来源类型
	var lylxJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInJb.do",{'tableName':'jb_lyfs'});
	if(lylxJson.status=="ok"){
		loadSelect("#form_cpinfo select[name=lylx]",lylxJson.rows,'id','name');
	}else{
		alertFunc("获取来源类型列表失败！");
		return false;
	}		
	//获取并填充拍摄方向
	var psfxJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do",{'tableName':'jb_psfx'});
	if(psfxJson.status=="ok"){
		loadSelect("#form_yx select[name=psfx]",psfxJson.rows,'id','name');
	}else{
		alertFunc("获取拍摄方向列表失败！");
		return false;
	}			
	//获取并填充摄影师
	var sysJson = ajaxResult("get",false,ProjectName+"/root.getUserListByRole.do",{'roleId':'sheyingshi'});
	if(sysJson.status=="ok"){
		loadSelect("#form_yx select[name=psrid]",sysJson.rows,'userid','username');
	}else{
		alertFunc("获取摄影师列表失败！");
		return false;
	}
	//获取并填充伤况主体
	var skztJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInXtjb.do",{'tableName':'xtjb_zt'});
	if(skztJson.status=="ok"){
		loadSelect("#form_wcqk select[name=skzt]",skztJson.rows,'id','name');
	}else{
		alertFunc("获取伤况主体列表失败！");
		return false;
	}	
	//获取并填充完残情况
	var wcqkJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInXtjb.do",{'tableName':'jb_wccd'});
	if(wcqkJson.status=="ok"){
		loadSelect("#form_wcqk select[name=wcqk]",wcqkJson.rows,'id','name');
	}else{
		alertFunc("获取完残情况列表失败！");
		return false;
	}	
	//获取并填充保存状态
	var bcztJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInJb.do",{'tableName':'jb_bczt'});
	if(bcztJson.status=="ok"){
		loadSelect("#form_wcqk select[name=bczt]",bcztJson.rows,'id','name');
	}else{
		alertFunc("获取保存状态列表失败！");
		return false;
	}	
	
   //设置返回按钮链接
   $("#returnLink").attr("href",'javascript:history.go(-1);');
   //获取藏品信息
   var cpInfo = ajaxResult("get",false,ProjectName+"/colmanage.getDbCp.do",{'id':cpid});
   //填充藏品信息到表单
   if(cpInfo.status=="ok"){
	  loadData("#form_cpinfo",cpInfo.data); 
	  if(cpInfo.data.cpfl1!=null && cpInfo.data.cpfl1!=""){
		  var cpfl1Json = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_cplb','id':cpInfo.data.cpfl1});
		  if(cpfl1Json.status=="ok"){
		    $('#form_cpinfo input[name=cpfl1]').val(cpfl1Json.rows[0].name);
		  }else{
			alertFunc("获取藏品分类1失败！");
			return false;
		  }	
	  }
	  if(cpInfo.data.cpfl3!=null && cpInfo.data.cpfl2!=""){	  
		  var cpfl2Json = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_cplb','id':cpInfo.data.cpfl2});
		  if(cpfl2Json.status=="ok"){
			  $('#form_cpinfo input[name=cpfl2]').val(cpfl2Json.rows[0].name);
		  }else{
			alertFunc("获取藏品分类2失败！");
			return false;
		  }		  	  
	  }
	  if(cpInfo.data.cpfl3!=null && cpInfo.data.cpfl3!=""){	
	  var cpfl3Json = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_cplb','id':cpInfo.data.cpfl3});	  
		  if(cpfl3Json.status=="ok"){
			  $('#form_cpinfo input[name=cpfl3]').val(cpfl3Json.rows[0].name);
		  }else{
			alertFunc("获取藏品分类3失败！");
			return false;
		  }	 
	  }
	  
	  if(cpInfo.data.cplb!=null && cpInfo.data.cplb!=""){	
		  var cplbJson = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_wwlb','id':cpInfo.data.cplb});	  
			  if(cplbJson.status=="ok"){
				  $('#form_cpinfo input[name=cplb]').val(cplbJson.rows[0].name);
			  }else{
				alertFunc("获取藏品类别失败！");
				return false;
			  }	 
	  }
	  
	  if(cpInfo.data.sd1!=null && cpInfo.data.sd1!=""){	
		  var sd1Json = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_nd','id':cpInfo.data.sd1});	  
			  if(sd1Json.status=="ok"){
				  $('#form_cpinfo input[name=sd1]').val(sd1Json.rows[0].name);
			  }else{
				alertFunc("获取时代1失败！");
				return false;
			  }	 
	  }
	  if(cpInfo.data.sd2!=null && cpInfo.data.sd2!=""){	
		  var sd2Json = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_nd','id':cpInfo.data.sd2});	  
			  if(sd2Json.status=="ok"){
				  $('#form_cpinfo input[name=sd2]').val(sd2Json.rows[0].name);
			  }else{
				alertFunc("获取时代2失败！");
				return false;
			  }	 
	  }
	  if(cpInfo.data.sd3!=null && cpInfo.data.sd3!=""){	
		  var sd3Json = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_nd','id':cpInfo.data.sd3});	  
			  if(sd3Json.status=="ok"){
				  $('#form_cpinfo input[name=sd3]').val(sd3Json.rows[0].name);
			  }else{
				alertFunc("获取时代3失败！");
				return false;
			  }	 
	  }
	  if(cpInfo.data.sd4!=null && cpInfo.data.sd4!=""){	
		  var sd4Json = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_nd','id':cpInfo.data.sd4});	  
			  if(sd4Json.status=="ok"){
				  $('#form_cpinfo input[name=sd4]').val(sd4Json.rows[0].name);
			  }else{
				alertFunc("获取时代3失败！");
				return false;
			  }	 
	  }
	  if(cpInfo.data.ctsldw!=null && cpInfo.data.ctsldw!=""){	
		  var sldwJson = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_ctsldw','id':cpInfo.data.ctsldw});	  
			  if(sldwJson.status=="ok"){
				  $('#form_cpinfo input[name=ctsldw]').val(sldwJson.rows[0].name);
			  }else{
				alertFunc("获取传统数量单位失败！");
				return false;
			  }	 
	  }
	  if(cpInfo.data.sjsldw!=null && cpInfo.data.sjsldw!=""){	
		  var sjsldwJson = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_sjsldw','id':cpInfo.data.sjsldw});	  
			  if(sldwJson.status=="ok"){
				  $('#form_cpinfo input[name=sjsldw]').val(sjsldwJson.rows[0].name);
			  }else{
				alertFunc("获取实际数量单位失败！");
				return false;
			  }	 
	  }
	  if(cpInfo.data.lylx!=null && cpInfo.data.lylx!=""){	
		  var lylxJson = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_lyfs','id':cpInfo.data.lylx});	  
			  if(lylxJson.status=="ok"){
				  $('#form_cpinfo input[name=lylx]').val(lylxJson.rows[0].name);
			  }else{
				alertFunc("获取来源类型失败！");
				return false;
			  }	 
	  }	  
   }     
   //获取藏品编号，并设置各个表单中的藏品编号
   $("input[name=cpbh]").val(cpid);
   //获取附属物列表
   createTable('#fswTable',ProjectName+'/colmanage.getFushuwuList.do','id',fswTblTitle,{'cpbh':cpid});
   //获取影像列表
   createTable('#yxTable',ProjectName+'/colmanage.getYingxiangList.do','id',yxTblTitle,{'cpbh':cpid});
   //获取附件列表
   createTable('#fjTable',ProjectName+'/colmanage.getFujianList.do','id',fjTblTitle,{'cpbh':cpid});
   //获取鉴定信息列表
   createTable('#jdyjTable',ProjectName+'/colmanage.getJiandingXinxiList.do','id',jdxxTblTitle,{'cpbh':cpid});
   //获取最新的完残信息
   loadWcqk(cpid);
   //获取完残影像列表	
   loadWcyxList(cpid);
   
   $("#return_btn").click(function(){
	    window.location.href=history.go(-1);
   })
})

//填充完残情况信息
function loadWcqk(cpbh){
	var wcqkJson = ajaxResult("get",false,ProjectName+"/colmanage.getDbWc.do",{'cpbh':cpbh});
	if(wcqkJson.status=="ok"){
		//loadData("#form_wcqk",wcqkJson.data);
		if(jQuery.isEmptyObject(wcqkJson.data)){
			return false;
		}
		if(wcqkJson.data.skzt!=null && wcqkJson.data.skzt!=""){
			var skztJson = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'xtjb_zt','id':wcqkJson.data.skzt});
			if(skztJson.status=="ok"){
				$('#form_wcqk input[name=skzt]').val(skztJson.rows[0].name);
			}else{
				alertFunc("获取伤况主体信息失败！");
				return false;
			}			
		}
		if(wcqkJson.data.wcqk!=null && wcqkJson.data.wcqk!=""){
			var wcqkvalJson = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_wccd','id':wcqkJson.data.wcqk});
			if(wcqkvalJson.status=="ok"){
				$('#form_wcqk input[name=wcqk]').val(wcqkvalJson.rows[0].name);	
			}else{
				alertFunc("获取完残情况信息失败！");
				return false;
			}			
		}
		if(wcqkJson.data.bczt!=null && wcqkJson.data.bczt!=""){
			var bcztJson = ajaxResult("get",false,ProjectName+"/sysmanage.getNameInJbByIdTableName.do",{'tableName':'jb_bczt','id':wcqkJson.data.bczt});
			if(bcztJson.status=="ok"){
				$('#form_wcqk input[name=bczt]').val(bcztJson.rows[0].name);
			}else{
				alertFunc("获取保存状态信息失败！");
				return false;
			}			
		}		
		$('#form_wcqk input[name=ssyy]').val(wcqkJson.data.ssyy);
		if(wcqkJson.data.sfxf==1){
			$('#form_wcqk input[name=sfxf]').val('是');
		}else if(wcqkJson.data.wcbz==0){
			$('#form_wcqk input[name=sfxf]').val('否');
		}	
		$('#form_wcqk textarea[name=ssms]').val(wcqkJson.data.ssms);
	}	
}

//填充完残影像信息
function loadWcyxList(cpbh){
	var imgHtml="";
	var wcyxJson = ajaxResult("get",false,ProjectName+"/colmanage.getDbWcYxList.do",{'cpbh':cpbh});
	if(wcyxJson.status=='ok'){
		$.each(wcyxJson.rows,function(index,content){
			imgHtml += "<div class='imgdiv'><img src='"+imageAddr+content["sldz"]+"'></div>";
		})		
		$("#wcyxDiv").html(imgHtml);
	}else{
		alertFunc("获取完残影像列表失败");
		return false;
	}	
}


//----------------------------------------------------
var fswTblTitle = [{
	        field: 'fswbh',
	        title: '附属物编号'
	    }, {
	        field: 'fswmc',
	        title: '附属物名称'
	    }, {
	        field: 'fswsl',
	        title: '附属物数量'
	    }, {
	        field: 'lrrmc',
	        title: '操作人'
	    }]

var yxTblTitle = [{
    field: 'sldz',
    title: '缩略影像',
    formatter: function(value, row, index) {     	
    	if(value!="" && value!=null)	
      	    return "<img src='"+imageAddr+value+"'>";    	
    	else
    		return "";
    }
}, {
    field: 'psfxms',
    title: '拍摄方向'
}, {
    field: 'psrmc',
    title: '拍摄人'
},{
    field: 'pssj',
    title: '拍摄时间'
},{
    field: 'sfyx',
    title: '代表影像',
    formatter: function(value, row, index) {     	
    	if(value==1)	
      	    return "是";
    	else
    		return "";
      	}
}]

var fjTblTitle = [{
	        field: 'wjmc',
	        title: '文件名'
	    }, {
	        field: 'lrsj',
	        title: '上传日期'
	    }, {
	        field: 'lrrmc',
	        title: '操作人'
	    }]

var jdxxTblTitle = [{
	        field: 'jdyy',
	        title: '鉴定原因'
	    }, {
	        field: 'jdr',
	        title: '鉴定人'
	    }, {
	        field: 'jddw',
	        title: '鉴定单位'
	    }, {
	        field: 'jdsj',
	        title: '鉴定时间'
	    }, {
	        field: 'lrrmc',
	        title: '操作人'
	    }]
//----------------------------------------------------
